package com.yuyue.springFramework.note08.entity;

import org.springframework.beans.BeansException;
import org.springframework.context.*;
import org.springframework.core.env.Environment;
import org.springframework.core.io.ResourceLoader;
import org.springframework.core.metrics.ApplicationStartup;
import org.springframework.util.StringValueResolver;

import javax.annotation.PostConstruct;

/**
 * 实现Aware相关接口
 */
public class MyAwreLoad implements EnvironmentAware,
        EmbeddedValueResolverAware,
        ResourceLoaderAware,
        ApplicationEventPublisherAware,
        MessageSourceAware,
        ApplicationStartupAware,
        ApplicationContextAware{

    @PostConstruct
    public void postConstruct1(){
        System.out.println("初始化方法1：postConstruct1");
    }

    @PostConstruct
    public void postConstruct2(){
        System.out.println("初始化方法2：postConstruct2");
    }

    @Override
    public void setEnvironment(Environment environment) {
        System.out.println("继承重写方法前，已注入相关Bean，并非发生相关事件时调用重写的方法" + (environment != null));
        System.out.println("1-环境信息：setEnvironment");
    }

    @Override
    public void setEmbeddedValueResolver(StringValueResolver resolver) {
        System.out.println("2-嵌入值解析：setEmbeddedValueResolver");
    }

    @Override
    public void setResourceLoader(ResourceLoader resourceLoader) {
        System.out.println("3-资源加载器：setResourceLoader");
    }

    @Override
    public void setApplicationEventPublisher(ApplicationEventPublisher applicationEventPublisher) {
        System.out.println("4-上下文事件发布器：setApplicationEventPublisher");
    }

    @Override
    public void setMessageSource(MessageSource messageSource) {
        System.out.println("5-消息源：setMessageSource");
    }

    @Override
    public void setApplicationStartup(ApplicationStartup applicationStartup) {
        System.out.println("6-容器启动：setApplicationStartup");
    }

    @Override
    public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
        System.out.println("7-上下文：setApplicationContext");
    }
}
